package com.tencent.system.service.impl;

import com.tencent.basic.util.PageList;
import com.tencent.system.domain.SystemDictionaryDetail;
import com.tencent.system.mapper.SystemDictionaryDetailMapper;
import com.tencent.system.query.SystemDictionaryDetailQuery;
import com.tencent.system.service.ISystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class SystemDictionaryDetailServiceImpl implements ISystemDictionaryDetailService {

    @Autowired
    private SystemDictionaryDetailMapper systemDictionaryDetailMapper;

    /**
     * 业务层实现类 ： 查询所有
     *
     * @return
     */
    @Override
    public List<SystemDictionaryDetail> queryAll() {
        return systemDictionaryDetailMapper.findAll();
    }

    /**
     * 业务层实现类 ： 查询单个
     *
     * @param id
     * @return
     */
    @Override
    public SystemDictionaryDetail queryById(Long id) {
        return systemDictionaryDetailMapper.findById(id);
    }

    /**
     * 业务层实现类 ： 删除
     *
     * @param id
     */
    @Override
    @Transactional
    public void delete(Long id) {
        systemDictionaryDetailMapper.delete(id);
    }

    /**
     * 业务层实现类 ： 添加
     *
     * @param systemDictionaryDetail
     */
    @Transactional
    @Override
    public void save(SystemDictionaryDetail systemDictionaryDetail) {
        systemDictionaryDetailMapper.save(systemDictionaryDetail);
    }

    /**
     * 业务层实现类 ： 修改
     *
     * @param systemDictionaryDetail
     */
    @Transactional
    @Override
    public void update(SystemDictionaryDetail systemDictionaryDetail) {
        systemDictionaryDetailMapper.update(systemDictionaryDetail);
    }

    /**
     * 业务层实现类 ：分页查询
     *
     * @param query
     * @return
     */
    @Override
    public PageList<SystemDictionaryDetail> queryPage(SystemDictionaryDetailQuery query) {
        // 先查询总条数 - 传query进去 是高级查询keyword 的需要
        Long totals = systemDictionaryDetailMapper.queryCount(query);
        // 如果没有数据 就返回一个new PageList<> 有默认值 0 和 空的ArrayList<>
        if (totals == 0) {
            return new PageList<>();
        }
        // 如果有数据 执行分页方法 query中有begin pageSize currentPage 获取数据
        List<SystemDictionaryDetail> data = systemDictionaryDetailMapper.queryData(query);

        // 将 总数和 数据返回 完成分页
        return new PageList<>(totals, data);
    }


    /**
     * 批量删除
     * @param ids
     */
    @Transactional
    @Override
    public void patchDelete(Long[] ids) {
        systemDictionaryDetailMapper.patchDelete(ids);
    }
}
